﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;
using BusinessObjects.BO_GetObjects;
using System.Globalization;
public partial class Pages_Index : PageBase
{
    private int cid = 2;
    private Int64 deal_id = 0;
    private string module_type, module_id, cache_key = string.Empty;
    private DataTable objDT = null;
    int category_id;
    private UserControl control = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        form1.Action = Request.RawUrl;

        category_id = Setting.getRequest(Request, "category_id", 2);
        if (!String.IsNullOrEmpty(Request["category_id"]))
        {
            cid = Convert.ToInt32(Request["category_id"]);
        }
        else
        {
            cid = 2;
        }

        LoadModule(1, plhdMain, cid);
        if (!IsPostBack)
        {
            this.Display();
            string script = "$(\".navBar ul li a\").removeClass('active');$(\".navBar ul li a#" + category_id.ToString() + "\").addClass('active');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Information", script, true);
        }
    }
    private void Display()
    {
        DataTable objDT = BO_portal_categories.SelectHomeMenu();
        //Response.Write(base.Lang.ToString());
        if (base.Lang)
        {
           foreach (DataRow row in objDT.Rows)
            {
                row["FULL_CATEGORY_NAME"] = row["FULL_CATEGORY_NAME_ENG"];
            }
        }
        rptHomeMenu.DataSource = objDT;
        rptHomeMenu.DataBind();
    }
    protected void LoadModule(int location_id, PlaceHolder _PlaceHolder, int CATEGORY_id)
    {
        try
        {
            _PlaceHolder.Controls.Clear();

            //cache_key = "PORTAL_MODULES_SELECT_HOME_" + cid + location_id;

            //if (Cache[cache_key] != null) {
            //    objDT = (DataTable)Cache[cache_key];
            //} else {
            objDT = BO_portal_modules.SelectHome(CATEGORY_id, location_id);
            Cache[cache_key] = objDT;
            //}

            if (objDT != null && objDT.Rows.Count > 0)
            {
                foreach (DataRow row in objDT.Rows)
                {
                    module_type = row["TYPE_NAME"].ToString();
                    module_id = row["MODULE_ID"].ToString();
                    control = (UserControl)Page.LoadControl("~/Controls/" + module_type + ".ascx");
                    control.Attributes.Add("ID", module_id);
                    _PlaceHolder.Controls.Add(control);
                }
            }
        }
        catch
        {
            throw;
        }
    }
    
    
    protected void LoadMenu()
    {

    }

    protected void lbtVI_Click(object sender, EventArgs e)
    {
        base.ApplyNewLanguage(new CultureInfo("vi-VN"));
        Session["lgg"] = "vn";
        Response.Redirect(Request.Url.ToString());
    }

    protected void lbtEN_Click(object sender, EventArgs e)
    {
        base.ApplyNewLanguage(new CultureInfo("en-US"));
        Session["lgg"] = "eng";
        Response.Redirect(Request.Url.ToString());
    }
}